home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 June: Reference Library / Dev.CD Jun 95 / Dev.CD Jun 95.toast / What's New? / New System Software Extensions / QuickDraw 3D ß / Programming / SampleCode / Modeller ƒ / modeller_menus.c < prev    next >
Encoding:
Text File  |  1995-04-05  |  23.9 KB  |  961 lines  |  [TEXT/MPS ]

  1. //        modeller_menus.c
  2. //
  3. //        Menu handling routines and utilities.
  4. //        
  5. //
  6. //        Author:        Pablo Fernicola, based on Rob Johnston's dragtext
  7. //        Date:        Wednesday, February 26, 1992
  8. //
  9. //    Modification History:
  10. //
  11. //    11/25/94    Nick    Started Factoring for AppleEvent senders, cleanup
  12. //
  13. //        Copyright © 1992-94 Apple Computer, Inc., All Rights Reserved
  14.  
  15.  
  16. #include <Drag.h>
  17. #include <Desk.h>
  18.  
  19. #include "Modeller_globals.h"
  20. #include "Modeller_prototypes.h"
  21. #include "Modeller_resources.h"
  22. #include "Modeller_AEVT.h"
  23.  
  24. #include "QD3DStorage.h"
  25. #include "QD3DStorage.h"
  26. #include "QD3DIO.h"
  27. #include "QD3DIO.h"
  28. #include "QD3DIO.h"
  29. #include "QD3DIO.h"
  30. #include "QD3DView.h"
  31. #include "QD3DTransform.h"
  32. #include "QD3DGeometry.h"
  33. #include "QD3DGroup.h"
  34. #include "QD3DShader.h"
  35. #include "QD3DShader.h"
  36. #include "QD3DLight.h"
  37. #include "QD3DRenderer.h"
  38. #include "QD3DAcceleration.h"
  39.  
  40. #include "Modeller_menus.h"
  41. #include "Modeller_document.h"
  42. #include "Modeller_file.h"
  43. #include "Modeller_windows.h"
  44. #include "Modeller_PICTImport.h"
  45. #include "Modeller_drag.h"
  46. #include "Modeller_offscreen.h"
  47. #include "Modeller_menus.h"
  48. #include "Modeller_utility.h"
  49. #include "Modeller_camera.h"
  50.  
  51. #define BETA_OR_LATER 1
  52.  
  53. #if !defined(BETA_OR_LATER) || (BETA_OR_LATER == 0)
  54. #include "Catwoman.h"
  55. #endif
  56.  
  57. static void DoCopy(DocumentPtr theDocument, Boolean cut);
  58. static short FindCheckItem(MenuHandle theMenu, short rangeStart, short rangeEnd);
  59. static short Check1Item(MenuHandle theMenu, short theItem, short rangeStart, short rangeEnd);
  60. static short ItemCheck(MenuHandle theMenu, short theItem);
  61. static short ToggleCheck(MenuHandle theMenu, short theItem);
  62. static void SetItemEnable(MenuHandle theMenu, short theItem, short enable);
  63. static short ItemStringToItem(Str255 theItemString, MenuHandle theMenu);
  64. static short FontToItem(short fontFamilyNumber);
  65. static short DoSpecialPaste(DocumentPtr theDocument);
  66. static void DoPaste(DocumentPtr theDocument);
  67.  
  68.  
  69. static void UpdateWindow( WindowPtr theWindow)
  70. {
  71.     GrafPtr    savedPort ;
  72.     
  73.     // just tell the toolbox that the window is bogus
  74.     GetPort(&savedPort) ;
  75.     SetPort(theWindow) ;
  76.     InvalRect( &theWindow->portRect ) ;
  77.     SetPort(savedPort) ;
  78. }
  79.  
  80.  
  81.  
  82.  
  83. static void DoCopy(DocumentPtr theDocument, Boolean cut)
  84. {
  85.     TQ3FileObject         fd;
  86.     TQ3StorageObject     st;
  87.     Handle                theData;
  88.     long                 anErr;
  89.     unsigned long        size;
  90.     PicHandle            thePicture;
  91.     GrafPtr                restorePort;
  92.     RGBColor            qdBgColor;
  93.     Boolean                didAllocate = false ;
  94.     
  95.     // Write the data to a strage object 
  96.  
  97.     // as of 1.0a3 handle storage objects break when increasing the size
  98.     // of the handle in increments with complex models.  To try to get
  99.     // around this we'll temporarily allocate a 1 meg handle. FIX THIS
  100.     if((theData = NewHandle( 1024 * 1024 )) != nil) {
  101.         MoveHHi( theData ) ;
  102.         HLock( theData ) ;
  103.         didAllocate = true ;
  104.         st = Q3HandleStorage_New( theData, GetHandleSize( theData ) );
  105.     }
  106.     else    
  107.         st = Q3HandleStorage_New(nil, 0);
  108.  
  109.     if (st == nil)
  110.     {
  111.         if( didAllocate )
  112.             DisposHandle( theData ) ;
  113.         return;
  114.     }
  115.     
  116.     fd = Q3File_New();
  117.     
  118.     if (fd == nil) {
  119.         Q3Object_Dispose(st);
  120.         if( didAllocate )
  121.             DisposHandle( theData ) ;
  122.         return;
  123.     }
  124.     
  125.     Q3File_SetStorage(fd, st);
  126.     
  127.         
  128.     Modeller_WriteScene(fd, 
  129.                         false,
  130.                         theDocument) ;
  131.     
  132.     theData = nil; size = 0;
  133.     
  134.     if( Q3HandleStorage_Get(st, &theData, &size) == kQ3Failure ) {
  135.         Q3Object_Dispose(st);
  136.         if( didAllocate )
  137.             DisposHandle( theData ) ;
  138.         return;
  139.     }
  140.     
  141.     /* Transfer the data to the scrap */
  142.     HLock(theData);
  143.     
  144.     GetPort( &restorePort);
  145.     SetPort( (GrafPtr) theDocument->theWindow);
  146.     
  147.     qdBgColor.red     = (unsigned short)65535;
  148.     qdBgColor.green = (unsigned short)65535;
  149.     qdBgColor.blue     = (unsigned short)65535;
  150.     RGBBackColor(&qdBgColor);
  151.     qdBgColor.red     = 0;
  152.     qdBgColor.green = 0;
  153.     qdBgColor.blue     = 0;
  154.     RGBForeColor(&qdBgColor);
  155.     thePicture = OpenPicture(&theDocument->theWindow->portRect);
  156.     EraseRect( &theDocument->theWindow->portRect ) ;
  157.     
  158.     if( DrawOffscreen(theDocument) == kQ3Failure ) {
  159.         goto memExit;
  160.     }
  161.     
  162.     ClosePicture();
  163.     
  164.     HLock( (Handle) thePicture);
  165.     
  166.     /* Initialize the scrap */
  167.     anErr = LoadScrap();
  168.     if (anErr != noErr) {
  169.         goto errorExit;
  170.     } else {
  171.         anErr = ZeroScrap();
  172.         if (anErr == noErr) {
  173.             anErr = PutScrap(size, '3DMF', (Ptr) *theData);
  174.             if (anErr == noErr) {
  175.                 anErr = PutScrap(GetHandleSize((Handle)thePicture), 'PICT', (Ptr) *thePicture);
  176.                 if (anErr == noErr) {
  177.                     anErr = UnloadScrap();
  178.                 }
  179.             }
  180.         }
  181.     }
  182.     
  183.     HUnlock(theData);
  184.  
  185.     if( cut == true ) {
  186.         Q3Object_Dispose(theDocument->documentGroup);
  187.         theDocument->documentGroup = nil;
  188.         SetPort(theDocument->theWindow) ;
  189.         InvalRect( &theDocument->theWindow->portRect) ;
  190.     }
  191.     
  192. errorExit:    
  193.     SetPort(restorePort);
  194.  
  195.     HUnlock((Handle)thePicture);
  196.     KillPicture(thePicture);
  197.     
  198. memExit:    
  199.     Q3Object_Dispose(st);
  200.     
  201.     if( didAllocate )
  202.         DisposHandle( theData ) ;
  203.         
  204.     Q3Object_Dispose(fd);
  205.     return;
  206. }
  207.  
  208. //
  209. //    Given a range of menu items and a menu, FindCheckItem returns the
  210. //    item number of the first checked item. If no items in the range
  211. //    are checked, FindCheckItem returns 0 (zero).
  212. //
  213.  
  214.  
  215. static short FindCheckItem(MenuHandle theMenu, short rangeStart, short rangeEnd)
  216.  
  217. {    short        theMark;
  218.  
  219.     while (rangeStart <= rangeEnd) {
  220.         GetItemMark(theMenu, rangeStart, &theMark);
  221.         if (theMark == checkMark)
  222.             return(rangeStart);
  223.         rangeStart++;
  224.     }
  225.  
  226.     return(0);
  227. }
  228.  
  229.  
  230. //
  231. //    Check1Item checks a single menu item in a range of menu items. theItem is
  232. //    the item number to check. rangeStart and rangeEnd denote a range of menu
  233. //    items that theItem belongs to. Check1Item checks theItem and removes
  234. //    any checks from the other items in the given range. Check1Item returns
  235. //    the item number of the checked item if a newly checked item is selected.
  236. //    If theItem was already checked or theItem was outside of the given range,
  237. //    Check1Item returns 0 (zero).
  238. //
  239.  
  240. static short Check1Item(MenuHandle theMenu, short theItem, short rangeStart, short rangeEnd)
  241.  
  242. {    short        theMark;
  243.  
  244.     if ((theItem < rangeStart) || (theItem > rangeEnd))
  245.         return(0);
  246.  
  247.     while (rangeStart <= rangeEnd) {
  248.         if (rangeStart != theItem)
  249.             CheckItem(theMenu, rangeStart, false);
  250.         rangeStart++;
  251.     }
  252.  
  253.     GetItemMark(theMenu, theItem, &theMark);
  254.  
  255.     if (theMark != checkMark) {
  256.         CheckItem(theMenu, theItem, true);
  257.         return(theItem);
  258.     } else {
  259.         return(0);
  260.     }
  261. }
  262.  
  263.  
  264. //
  265. //    ItemCheck returns true if the given menu item is checked, false otherwise.
  266. //
  267.  
  268. static short ItemCheck(MenuHandle theMenu, short theItem)
  269.  
  270. {    short        theMark;
  271.  
  272.     GetItemMark(theMenu, theItem, &theMark);
  273.     return(theMark == checkMark);
  274.  
  275. }
  276.  
  277.  
  278. //
  279. //    ToggleCheck toggles the check mark on the given menu item. ToggleCheck
  280. //    returns true if the item becomes checked and false if the item becomes
  281. //    unchecked.
  282. //
  283.  
  284. static short ToggleCheck(MenuHandle theMenu, short theItem)
  285.  
  286. {    short        theMark;
  287.  
  288.     GetItemMark(theMenu, theItem, &theMark);
  289.     CheckItem(theMenu, theItem, theMark = (theMark != checkMark));
  290.     return(theMark);
  291. }
  292.  
  293.  
  294. //
  295. //    SetItemEnable enables or disables a menu item depending on the value
  296. //    of the enable parameter.
  297. //
  298.  
  299. static void SetItemEnable(MenuHandle theMenu, short theItem, short enable)
  300.  
  301. {
  302.     if (enable) {
  303.         EnableItem(theMenu, theItem);
  304.     } else {
  305.         DisableItem(theMenu, theItem);
  306.     }
  307. }
  308.  
  309.  
  310. //
  311. //    Given a string and a menu, ItemStringToItem will return the item number
  312. //    of the last item that matches the string.
  313. //
  314.  
  315. static short ItemStringToItem(Str255 theItemString, MenuHandle theMenu)
  316.  
  317. {    short        index;
  318.     Str255        theString;
  319.  
  320.     index = CountMItems(theMenu);
  321.     while (index) {
  322.         GetItem(theMenu, index, theString);
  323.         if (PStrCmp( (char *) theString, (char *) theItemString))
  324.             return(index);
  325.         index--;
  326.     }
  327.     return(0);
  328. }
  329.  
  330.  
  331. static short FontToItem(short fontFamilyNumber)
  332.  
  333. {    Str255        fontName;
  334.  
  335.     GetFontName(fontFamilyNumber, fontName);
  336.     return(ItemStringToItem(fontName, GetMHandle(idDisplayMenu)));
  337. }
  338.  
  339.  
  340. //
  341. //    PrepareMenus is called before the user pulls down a menu from the menu
  342. //    bar or types a command key equivalent. PrepareMenus enables and disables
  343. //    menu items within the current program context. Any other menu related
  344. //    setup may be performed here.
  345. //
  346.  
  347. void PrepareMenus(void)
  348.  
  349. {    MenuHandle        theMenu;
  350.     DocumentPtr theDocument;
  351.     short            teSelection, theMode;
  352.     Str255            theStr;
  353.  
  354.     theDocument = GetDocumentFromWindow(FrontWindow());
  355.     teSelection = (short) theDocument->documentGroup;
  356.  
  357.     theMenu = GetMHandle(idFileMenu);
  358.  
  359.     SetItemEnable(theMenu, NewItem,   gDocumentCount < MaxDocumentCount);
  360.     SetItemEnable(theMenu, OpenItem,  gDocumentCount < MaxDocumentCount);
  361.  
  362.     SetItemEnable(theMenu, CloseItem, theDocument != 0L);
  363.     SetItemEnable(theMenu, SaveItem, (theDocument) && (theDocument->dirty));
  364.     SetItemEnable(theMenu, SaveAsItem, theDocument != 0L);
  365.     SetItemEnable(theMenu, RevertItem, (theDocument) &&
  366.                                        (theDocument->theFileSpec.parID != 0 ) &&
  367.                                        (theDocument->theFileSpec.vRefNum != 0 ));
  368.  
  369.     SetItemEnable(theMenu, PageSetupItem, false);
  370.     SetItemEnable(theMenu, PrintItem, false);
  371.  
  372.     theMenu = GetMHandle(idEditMenu);
  373.  
  374.     GetIndString(theStr, MenuStringsID, gCanUndoDrag);
  375.     SetItem(theMenu, iUndo, theStr);
  376.     SetItemEnable(theMenu, iUndo, gCanUndoDrag != slCantUndo);
  377.  
  378.     SetItemEnable(theMenu, iCut, teSelection);
  379.     SetItemEnable(theMenu, iCopy, teSelection);
  380.     SetItemEnable(theMenu, iPaste, theDocument != 0L);
  381.     SetItemEnable(theMenu, iClear, teSelection);
  382.     SetItemEnable(theMenu, iSelectAll, theDocument != 0L);
  383.     SetItemEnable(theMenu, iShowClipboard, false);
  384.  
  385.     theMenu = GetMHandle(idDisplayMenu);
  386.  
  387.     SetItemEnable(theMenu, iShaded, false);
  388.     SetItemEnable(theMenu, iLighted, false);
  389.     SetItemEnable(theMenu, iAnimated, false);
  390.     SetItemEnable(theMenu, iRenderer, false);
  391.     SetItemEnable(theMenu, iBackFacing, false);
  392.     
  393.     if (theDocument) {
  394.         theMode = 0;
  395.  
  396.         if( theDocument->documentGroup) {
  397.             MenuHandle        subMenu;
  398.  
  399.             SetItemEnable(theMenu, iShaded, true);
  400.  
  401.             subMenu = GetMenu(idStyleMenu);
  402.  
  403.             CheckItem(subMenu, iGouraud, false);
  404.             CheckItem(subMenu, iPhong, false);
  405.             CheckItem(subMenu, iFlat, false);
  406.  
  407.             if( theDocument->currentInterpolation == kQ3InterpolationStyleNone) {
  408.                 CheckItem(subMenu, iFlat, true);
  409.             } else if( theDocument->currentInterpolation == kQ3InterpolationStylePixel) {
  410.                 CheckItem(subMenu, iPhong, true);
  411.             } else {
  412.                 CheckItem(subMenu, iGouraud, true);
  413.             }
  414.  
  415.             SetItemEnable(theMenu, iRenderer, true);
  416.             subMenu = GetMenu(idRendererMenu);
  417.  
  418.             CheckItem(subMenu, iWF, false);
  419.             CheckItem(subMenu, iZB, false);
  420.             CheckItem(subMenu, iCTSW, false);
  421.             CheckItem(subMenu, iCTHW, false);
  422.  
  423.             {
  424.                 TQ3Object    renderer;
  425.                 
  426.                 Q3View_GetRenderer(theDocument->theView, &renderer);
  427.                 
  428.                 switch(Q3Object_GetLeafType(renderer)) {
  429.                     case kQ3RendererTypeWireFrame:
  430.                         CheckItem(subMenu, iWF, true);
  431.                     break;
  432. #if defined(ESCHER_VER_15) && ESCHER_VER_15
  433.                     case kQ3RendererTypeZBuffer:
  434.                         CheckItem(subMenu, iZB, true);
  435.                     break;
  436. #endif
  437.                     case kQ3RendererTypeInteractive:
  438.                         if(!gUsingHardware) {
  439.                             CheckItem(subMenu, iCTSW, true);
  440.                         }
  441.                         else {
  442.                             CheckItem(subMenu, iCTHW, true);
  443.                         }
  444.                     break;
  445.                     default:
  446.                     break;
  447.                 }
  448.                 Q3Object_Dispose(renderer);
  449.             } 
  450.             
  451.             SetItemEnable(theMenu, iLighted, true);
  452.             if( theDocument->light == kQ3True) {
  453.                 CheckItem(theMenu, iLighted, true);
  454.             } else {
  455.                 CheckItem(theMenu, iLighted, false);
  456.             }
  457.  
  458.             SetItemEnable(theMenu, iAnimated, true);
  459.             subMenu = GetMenu(idAnimateMenu);
  460.  
  461.             if( theDocument->animateLights == kQ3True) {
  462.                 CheckItem(subMenu, iLights, true);
  463.             } else {
  464.                 CheckItem(subMenu, iLights, false);
  465.             }
  466.  
  467.             if( theDocument->animateModel == kQ3True) {
  468.                 CheckItem(subMenu, iModel, true);
  469.             } else {
  470.                 CheckItem(subMenu, iModel, false);
  471.             }
  472.             
  473.             SetItemEnable(theMenu, iBackFacing, true);
  474.         }
  475.     }
  476. }
  477.  
  478.  
  479. static short DoSpecialPaste(DocumentPtr theDocument)
  480.  
  481. {    long        size, offset;
  482.     Handle        theData;
  483.  
  484.     size = GetScrap(0L, 'UPRC', &offset);
  485.  
  486.     if (size <= 0)
  487.         return(0);
  488.  
  489.     theData = NewHandle(size);
  490.     GetScrap(theData, 'UPRC', &offset);
  491.  
  492.     HLock(theData);
  493.     PutScrap(size, 'test', *theData);
  494.  
  495.     HUnlock(theData);
  496.     DisposeHandle(theData);
  497.  
  498.     return(0);
  499. }
  500.  
  501. static void DoPaste(DocumentPtr theDocument)
  502.  
  503. {    long            size, offset;
  504.     Handle            theData;
  505.     long            anErr= noErr;
  506.     TQ3SharedObject    viewHints ;
  507.     
  508.     anErr = LoadScrap();
  509.     if (anErr == noErr) {
  510.         size = GetScrap(0L, '3DMF', &offset);
  511.     
  512.         if (size > 0) {
  513.             TQ3FileObject         fd;
  514.             TQ3StorageObject         storage;
  515.             TQ3Object             objects = nil;
  516.     
  517.             theData = NewHandle(size);
  518.             if( theData ) {
  519.                 GetScrap(theData, '3DMF', &offset);
  520.             
  521.                 HLock(theData);
  522.         
  523.                 /* Read from clipboard */
  524.                 storage = Q3MemoryStorage_New((unsigned char *) *theData, (unsigned long) size);
  525.                 
  526.                 if (storage == nil)
  527.                     goto bail;
  528.                 
  529.                 fd = Q3File_New();
  530.                 Q3File_SetStorage(fd, storage);
  531.                 Q3Object_Dispose(storage);
  532.                 
  533.                 if (fd == nil)
  534.                     goto bail;
  535.                 
  536.                 Modeller_ReadScene(    fd,
  537.                                     false,
  538.                                     &viewHints,
  539.                                     &theDocument->documentGroup) ;
  540.                 
  541.                 ModellerDocument_UpdateView( theDocument, viewHints ) ;
  542.                 
  543.                 AdjustLightsPositions(theDocument);
  544.             
  545.                 if (viewHints != NULL )
  546.                     Q3Object_Dispose(viewHints);
  547.  
  548.                 DrawOffscreen(theDocument);
  549.                 // DrawControls(theDocument->theWindow);
  550.                 DoDrawGrowIcon(theDocument->theWindow);
  551.             bail:
  552.                 Q3Object_Dispose(fd);
  553.         
  554.                 HUnlock(theData);
  555.                 DisposeHandle(theData);
  556.             }
  557.         } else {
  558.             size = GetScrap(0L,'PICT', &offset);
  559.             
  560.             if( size > 0 && theDocument->documentGroup) {
  561.                 TQ3StoragePixmap         textureImage;        
  562.                 theData = NewHandle(size);
  563.                 
  564.                 if( theData ) {
  565.                     GetScrap(theData, 'PICT', &offset);
  566.                 
  567.                     HLock(theData);
  568.             
  569.                     if( TextureFromPICT( (PicHandle) theData, &textureImage) == kQ3True ) {
  570.     
  571.                         if( AddTextureToDocument( theDocument, &textureImage) == kQ3Success ) {
  572.     
  573.                             DrawOffscreen(theDocument);
  574.                             
  575.                             // DrawControls(theDocument->theWindow);
  576.                             DoDrawGrowIcon(theDocument->theWindow);
  577.                         } else {
  578.                             Alert(130, 0L);
  579.                         }
  580.                     } else {
  581.                         Alert(130, 0L);
  582.                     }
  583.                     HUnlock(theData);
  584.                     DisposeHandle(theData);
  585.                 } else {
  586.                     Alert(130, 0L);
  587.                 }
  588.             }
  589.         }
  590.     }
  591. }
  592.  
  593.  
  594. //
  595. //    DoMenuCommand dispatches menu command routines from a menu select parameter.
  596. //    This function is called when the user selects a menu item with the mouse
  597. //    or types a command key equivalent.
  598. //
  599.  
  600. void DoMenuCommand(long select)
  601.  
  602. {    short        theMenuID, theItem, result;
  603.     MenuHandle    theMenu;
  604.     Str255        theName;
  605.     WindowPtr    theWindow;
  606.     DocumentPtr theDocument;
  607.  
  608.     theDocument = GetDocumentFromWindow(theWindow = FrontWindow());
  609.  
  610.     theItem   = LoWord(select);
  611.     theMenuID = HiWord(select);
  612.     theMenu   = GetMHandle(theMenuID);
  613.     switch(theMenuID) {
  614.         case idAppleMenu:
  615.             switch(theItem) {
  616.                 case AboutItem:
  617.                     result = Alert(256, 0L);
  618.                     break;
  619.                 default:
  620.                     GetItem(GetMHandle(idAppleMenu), theItem, theName);
  621.                     OpenDeskAcc(theName);
  622.             }
  623.             break;
  624.         case idFileMenu:
  625.             switch(theItem) {
  626.             
  627.                 case NewItem:
  628.                     DoNewDocument();
  629.                     break;
  630.                     
  631.                 case OpenItem:
  632.                     DoOpenDocument(theDocument);
  633.                     break;
  634.                     
  635.                 case CloseItem:
  636.                     if (theDocument) {
  637.                         (void)CloseDocument(theDocument);        // it's not important what the result is here
  638.                     }
  639.                     break;
  640.                     
  641.                 case SaveItem:
  642.                     if (theDocument)
  643.                         DidSaveDocument(theDocument);
  644.                     break;
  645.                     
  646.                 case SaveAsItem:
  647.                     if (theDocument)
  648.                         DoSaveAsDocument(theDocument);
  649.                     break;
  650.                     
  651.                 case RevertItem:
  652.                     if (theDocument)
  653.                         DoRevertDocument(theDocument);
  654.                     break;
  655.                     
  656.                 case QuitItem:
  657.                     // to quit we just send ourselves an appleEvent
  658.                     SendQuitApp() ;
  659.                     break;
  660.             }
  661.             break;
  662.         case idEditMenu:
  663.             switch(theItem) {
  664.                 case iUndo:
  665.                     break;
  666.                     
  667.                 case iCut:
  668.                     if (theDocument) {
  669.                         DoCopy(theDocument, true);
  670.                     }
  671.                     break;
  672.                     
  673.                 case iCopy:
  674.                     if (theDocument) {
  675.                         DoCopy(theDocument, false);
  676.                     }
  677.                     break;
  678.                     
  679.                 case iPaste:
  680.                     if (theDocument) {
  681.                         DoPaste(theDocument);
  682.                     }
  683.                     UpdateWindow( theDocument->theWindow ) ;
  684.                      break;
  685.                     
  686.                 case iClear:
  687.                     break;
  688.                     
  689.                 case iSelectAll:
  690.                     break;
  691.                     
  692.             }
  693.             break;
  694.         case idDisplayMenu:
  695.  
  696.             switch(theItem) {
  697.                 case iLighted:
  698.                     if( theDocument->light == kQ3True) {
  699.                         TQ3GroupPosition        lightPosition;
  700.                         TQ3LightObject        theLight;
  701.                         TQ3GroupObject        lightGroup;
  702.                                 
  703.                         theDocument->light = kQ3False;
  704.                         
  705.                         Q3View_GetLightGroup(theDocument->theView, &lightGroup);
  706.                         Q3Group_GetFirstPosition(lightGroup, &lightPosition);
  707.                         
  708.                         /* First one is always on, skip */
  709.                         Q3Group_GetNextPosition(lightGroup, &lightPosition);
  710.                         Q3Group_GetPositionObject(lightGroup, lightPosition, &theLight);
  711.                         Q3Light_SetState(theLight,kQ3False);
  712.                         Q3Object_Dispose(theLight);                        
  713.                         
  714.                         Q3Group_GetNextPosition(lightGroup, &lightPosition);
  715.                         Q3Group_GetPositionObject(lightGroup, lightPosition, &theLight);
  716.                         Q3Light_SetState(theLight,kQ3False);                        
  717.                         Q3Object_Dispose(theLight);                        
  718.                         
  719.                         Q3Group_GetNextPosition(lightGroup, &lightPosition);
  720.                         Q3Group_GetPositionObject(lightGroup, lightPosition, &theLight);
  721.                         Q3Light_SetState(theLight,kQ3False);                        
  722.                         Q3Object_Dispose(theLight);                        
  723.  
  724.                         Q3Object_Dispose(lightGroup);
  725.                         CheckItem(theMenu, theItem, false);
  726.                     }else {    
  727.                         TQ3GroupPosition        lightPosition;
  728.                         TQ3LightObject        theLight;
  729.                         TQ3GroupObject    lightGroup;
  730.                                 
  731.                         theDocument->light = kQ3True;
  732.                         
  733.                         Q3View_GetLightGroup(theDocument->theView, &lightGroup);
  734.                         Q3Group_GetFirstPosition(lightGroup, &lightPosition);
  735.                         
  736.                         /* First one is always on, skip */
  737.                         Q3Group_GetNextPosition(lightGroup, &lightPosition);
  738.                         Q3Group_GetPositionObject(lightGroup, lightPosition, &theLight);
  739.                         Q3Light_SetState(theLight,kQ3True);
  740.                         Q3Object_Dispose(theLight);                        
  741.                         
  742.                         Q3Group_GetNextPosition(lightGroup, &lightPosition);
  743.                         Q3Group_GetPositionObject(lightGroup, lightPosition, &theLight);
  744.                         Q3Light_SetState(theLight,kQ3True);                        
  745.                         Q3Object_Dispose(theLight);                        
  746.                         
  747.                         Q3Group_GetNextPosition(lightGroup, &lightPosition);
  748.                         Q3Group_GetPositionObject(lightGroup, lightPosition, &theLight);
  749.                         Q3Light_SetState(theLight,kQ3True);                        
  750.                         Q3Object_Dispose(theLight);                        
  751.  
  752.                         Q3Object_Dispose(lightGroup);
  753.                         
  754.                         CheckItem(theMenu, theItem, true);
  755.                     }
  756.                         
  757.                     DrawOffscreen(theDocument);
  758.                     UpdateWindow( theDocument->theWindow ) ;
  759.                     if( theDocument->viewHints ) {
  760.                         Q3Object_Dispose(theDocument->viewHints);
  761.                     }
  762.                     theDocument->viewHints = Q3ViewHints_New(theDocument->theView);
  763.                     DoDrawGrowIcon(theDocument->theWindow);
  764.                     break;
  765.                     
  766.                 default:
  767.                     break;
  768.             }
  769.             break;
  770.         case idAnimateMenu:
  771.             if( theItem == iModel ) {
  772.                 if( theDocument->animateModel == kQ3True) {
  773.                     theDocument->animateModel = kQ3False;
  774.                     CheckItem(theMenu, theItem, false);
  775.                 }else {
  776.                     theDocument->animateModel = kQ3True;
  777.                     CheckItem(theMenu, theItem, true);
  778.                 }
  779.             } else if( theItem == iLights) {
  780.                 if( theDocument->animateLights == kQ3True) {
  781.                     theDocument->animateLights = kQ3False;
  782.                     CheckItem(theMenu, theItem, false);
  783.                 }else {
  784.                     theDocument->animateLights = kQ3True;
  785.                     CheckItem(theMenu, theItem, true);
  786.                 }
  787.             }    
  788.         break;
  789.  
  790.         case idRendererMenu:
  791.             {
  792.                 TQ3DrawContextObject        myDrawContext;
  793.                 // set the doupble buffer state to false, make the active buffer
  794.                 // to be the front buffer
  795.                 gUsingHardware = false ;
  796.                 Q3View_GetDrawContext(theDocument->theView, &myDrawContext) ;
  797.                 Q3DrawContext_SetDoubleBufferState(  myDrawContext, kQ3True ) ;
  798.                 Q3Object_Dispose( myDrawContext ) ;
  799.             }
  800.             switch(theItem) {
  801.                 case iWF:
  802.                     Q3View_SetRendererByType(theDocument->theView,kQ3RendererTypeWireFrame);
  803.                     CheckItem(theMenu, iCTHW, false);
  804.                     CheckItem(theMenu, iCTSW, false);
  805.                     CheckItem(theMenu, iZB, false);
  806.                     CheckItem(theMenu, iWF, true);
  807.                     theDocument->shaded = kQ3False;
  808.                     break;
  809. #if defined(ESCHER_VER_15) && ESCHER_VER_15
  810.                 case iZB:
  811.                     Q3View_SetRendererByType(theDocument->theView,kQ3RendererTypeZBuffer);
  812.                     CheckItem(theMenu, iWF, false);
  813.                     CheckItem(theMenu, iCTHW, false);
  814.                     CheckItem(theMenu, iCTSW, false);
  815.                     CheckItem(theMenu, iZB, true);
  816.                     theDocument->shaded = kQ3True;
  817.                     break;
  818. #endif
  819.                 case iCTSW:
  820.                     {
  821.                         TQ3RendererObject rendererObject;
  822.                         
  823.                         rendererObject = Q3Renderer_NewFromType(kQ3RendererTypeInteractive);
  824.                         Q3View_SetRenderer(theDocument->theView,rendererObject);
  825.                         Q3InteractiveRenderer_SetDoubleBufferBypass (rendererObject, kQ3True);                        
  826.                         Q3InteractiveRenderer_SetPreferences(rendererObject, ZcVendor_Apple, ZcEngine_AppleSW);
  827.                         Q3Object_Dispose(rendererObject);
  828.  
  829.                         CheckItem(theMenu, iWF, false);
  830.                         CheckItem(theMenu, iZB, false);
  831.                         CheckItem(theMenu, iCTHW, false);
  832.                         CheckItem(theMenu, iCTSW, true);
  833.                         theDocument->shaded = kQ3True;
  834.                     }
  835.                     break;
  836.                 case iCTHW:
  837.                     {
  838.                         TQ3DrawContextObject        myDrawContext;
  839.                         TQ3RendererObject             rendererObject;
  840.                         
  841.                         // set the doupble buffer state to false, make the active buffer
  842.                         // to be the front buffer
  843.                         gUsingHardware = true ;
  844.  
  845.                         Q3View_GetDrawContext(theDocument->theView, &myDrawContext) ;
  846.                         Q3DrawContext_SetDoubleBufferState(  myDrawContext, kQ3False ) ;
  847.                         Q3Object_Dispose( myDrawContext ) ;
  848.                         
  849.                         
  850.                         rendererObject = Q3Renderer_NewFromType(kQ3RendererTypeInteractive);
  851.                         Q3View_SetRenderer(theDocument->theView,rendererObject);
  852.                         Q3InteractiveRenderer_SetDoubleBufferBypass (rendererObject, kQ3True);                        
  853.                         Q3InteractiveRenderer_SetPreferences(rendererObject, ZcVendor_BestChoice, 0);
  854.                         Q3Object_Dispose(rendererObject);
  855.  
  856.                         CheckItem(theMenu, iWF, false);
  857.                         CheckItem(theMenu, iZB, false);
  858.                         CheckItem(theMenu, iCTSW, false);
  859.                         CheckItem(theMenu, iCTHW, true);
  860.                         theDocument->shaded = kQ3True;
  861.                     }
  862.                     break;
  863.             }
  864.             DrawOffscreen(theDocument) ;
  865.             UpdateWindow( theDocument->theWindow ) ;
  866.             if( theDocument->viewHints ) {
  867.                 Q3Object_Dispose(theDocument->viewHints);
  868.             }
  869.             theDocument->viewHints = Q3ViewHints_New(theDocument->theView);
  870.             DoDrawGrowIcon(theDocument->theWindow) ;
  871.             break ;
  872.             
  873.         // menu to allow modification of the backfacing style
  874.         case idBackfacingMenu:
  875.             switch(theItem) {
  876.             
  877.                 case iDrawBoth:
  878.  
  879.                     Q3BackfacingStyle_Set(theDocument->backfacingStyle, kQ3BackfacingStyleBoth);
  880.                     CheckItem(theMenu, iDrawBoth, true);
  881.                     CheckItem(theMenu, iRemoveBackfacing, false);
  882.                     CheckItem(theMenu, iFlipNormals, false);
  883.                     break;
  884.                     
  885.                 case iRemoveBackfacing:
  886.                 
  887.                     Q3BackfacingStyle_Set(theDocument->backfacingStyle, kQ3BackfacingStyleRemove);
  888.                     CheckItem(theMenu, iDrawBoth, false);
  889.                     CheckItem(theMenu, iRemoveBackfacing, true);
  890.                     CheckItem(theMenu, iFlipNormals, false);
  891.                     break;
  892.                     
  893.                 case iFlipNormals:
  894.  
  895.                     Q3BackfacingStyle_Set(theDocument->backfacingStyle, kQ3BackfacingStyleFlip);
  896.                     CheckItem(theMenu, iDrawBoth, false);
  897.                     CheckItem(theMenu, iRemoveBackfacing, false);
  898.                     CheckItem(theMenu, iFlipNormals, true);
  899.                     break;
  900.                     
  901.             }
  902.  
  903.             DrawOffscreen(theDocument);
  904.             UpdateWindow( theDocument->theWindow ) ;
  905.             
  906.             // DrawControls(theDocument->theWindow);
  907.             DoDrawGrowIcon(theDocument->theWindow);
  908.             break;
  909.         case idStyleMenu:
  910. //            DisableUndoDrag();
  911.             switch(theItem){
  912.                 case iFlat:
  913.                     theDocument->currentInterpolation = kQ3InterpolationStyleNone;
  914.                     CheckItem(theMenu, iGouraud, false);
  915.                     CheckItem(theMenu, iPhong, false);
  916.                     CheckItem(theMenu, iFlat, true);
  917.                     break;
  918.                 case iGouraud:
  919.                     theDocument->currentInterpolation = kQ3InterpolationStyleVertex;
  920.                     CheckItem(theMenu, iPhong, false);
  921.                     CheckItem(theMenu, iFlat, false);
  922.                     CheckItem(theMenu, iGouraud, true);
  923.                     break;
  924.                 case iPhong:
  925.                     theDocument->currentInterpolation = kQ3InterpolationStylePixel;
  926.                     CheckItem(theMenu, iGouraud, false);
  927.                     CheckItem(theMenu, iFlat, false);
  928.                     CheckItem(theMenu, iPhong, true);
  929.                     break;
  930.             }
  931.             
  932.             DrawOffscreen(theDocument);
  933.             UpdateWindow( theDocument->theWindow ) ;
  934.             DoDrawGrowIcon(theDocument->theWindow);
  935.             break;
  936. #ifdef PODIUM_APP
  937.         case 231:
  938.             switch(theItem){
  939.                 case 5:
  940.                     if( theDocument->animateModel == kQ3True )
  941.                         theDocument->animateModel = kQ3False ;
  942.                     else
  943.                         theDocument->animateModel = kQ3True ;
  944.                     break ;
  945.                 default:
  946.                     break ;
  947.             }
  948.             break ;
  949. #endif            
  950.         
  951.         default:
  952.             break;
  953.     }
  954.  
  955. //    if ((theDocument = GetDocumentFromWindow(FrontWindow())) != nil)
  956. //        TEGetHiliteRgn(theDocument->hiliteRgn, theDocument->theTE);
  957.  
  958.     HiliteMenu(0);
  959. }
  960.  
  961.